<body>
  <img src="img/user.png" width="48" height="48" class="filter-criteria left act">
  <img src="img/guild.png" width="48" height="48" class="filter-criteria right">
  <img src="img/fb_login.png" width="134" height="54" id="fb-login" onclick="window.location='functions/login-facebook.php';" style="display:none;cursor:pointer;z-index:101;position:fixed;left:35%; top:40%;">
  <img src="img/tw_login.png" width="130" height="52" id="tw-login" onclick="window.location='functions/login-twitter.php';" style="display:none;cursor:pointer;z-index:101;position:fixed;right:35%; top:40%;">
  <script type="text/javascript">
    cur_coff = -999;
  </script>
  <div id="loading"<?=!isset($_SESSION['character'])? 'style="display:none"':''?> onClick="if($('img',this).not(':visible')){$(this).hide();$('#fb-login,#tw-login').hide();}">
    <img src="img/loading.gif" />
  </div>
  <table id="table-main"<?=!isset($_SESSION['character'])? 'style="display:none"':''?>>
    <tr>
      <td id="character-details">
        <img src="img/beta.png" id="beta" title="Version 1.<?=$svn_revision_number?>"/>
        <div class="data-container">
          <div class="data-header">
            <img src="img/<?=strtolower(getClassName($character_data[29]))?>.png" style="position:absolute;top:13px;left:27px;padding:0;" />
            <form method="post">
              <input type="hidden" name="filter_criteria[][search]" value="user">
              <input type="text" name="character" value="<?=$character?>">
            </form>
          </div>
<?php if($character != '') {?>
          <div class="data-div">
            <div style="visibility:hidden"><?=getClassName($character_data[29])?></div>
            <div><?=$lang_label['ust_level']?>: <a title="<?=$character_data[8].'/'.$character_data[9]?>"><?=$character_data[7]?></a></div>
            <div><?=$lang_label['ust_strength']?>: <a<?=(($character_data[35]=='0')?'>':' title="+'.$character_data[35].'">').($character_data[35]+$character_data[30])?></a></div>
            <div><?=$lang_label['ust_dexterity']?>: <a<?=(($character_data[36]=='0')?'>':' title="+'.$character_data[36].'">').($character_data[36]+$character_data[31])?></a></div>
            <div><?=$lang_label['ust_intelligence']?>: <a<?=(($character_data[37]=='0')?'>':' title="+'.$character_data[37].'">').($character_data[37]+$character_data[32])?></a></div>
            <div><?=$lang_label['ust_constitution']?>: <a<?=(($character_data[38]=='0')?'>':' title="+'.$character_data[38].'">').($character_data[38]+$character_data[33])?></a></div>
            <div><?=$lang_label['ust_luck']?>: <a<?=(($character_data[39]=='0')?'>':' title="+'.$character_data[39].'">').($character_data[39]+$character_data[34])?></a></div>
            <div><?=$lang_label['ust_damage']?>: <?=round($character_data[146]*(1+getMainStat($character_data)/10)).'-'.round($character_data[147]*(1+getMainStat($character_data)/10)).'(<a>'.getDPS($character_data)?></a>)</div>
            <div><?=$lang_label['ust_hitpoints']?>: <a><?=getHP($character_data)?></a></div>
            <div><?=$lang_label['ust_critical']?>: <?=getCrit($character_data)?> (<b><a id="my-crit"></a></b>)</div>
            <div><?=$lang_label['ust_res']?>: <a id="my-res"></a></div>
            <div><?=$lang_label['ust_armor']?>: <a><?=getArmor($character_data)?></a></div>
            <?=(($_script_debug == 1)?'<pre style="overflow:auto;height:200px;">'.implode("\n",$character_data).'</pre>':'')?>
          </div>
<?}?>
        </div>
      </td>
      <td valign="top">
        <table id="table-ranks">
          <thead>
            <tr>
              <th style="width:40px"><?=$lang_label['int_rang']?></th>
              <th style="width:119px"><?=$lang_label['int_name']?></th>
              <th style="width:112px"><?=$lang_label['int_clan']?></th>
              <th style="width:20px"><?=$lang_label['int_level']?></th>
              <th style="width:43px"><?=$lang_label['int_honor']?></th>
              <th style="width:68px"><?=$lang_label['int_cofficient']?></th>
            </tr>
          </thead>
<?php		
  if($character != ''){
    for($i = 0; $i< (sizeof($opponents_data)-1)/5; $i++){
      $rank = (strpos($opponents_data[($i*5)],'-') === false)?array(0,$opponents_data[($i*5)]):explode('-',$opponents_data[($i*5)]);
      ?>
      <tr<?=($i == 0)?' class="current"':''?> id="row-<?=$rank[1]?>"><td><?=$rank[1]?></td><td><?=$opponents_data[($i*5)+1]?></td><td><?=$opponents_data[($i*5)+2]?></td><td><?=str_replace('-','',$opponents_data[($i*5)+3])?></td><td><?=$opponents_data[($i*5)+4]?></td><td></td></tr>
    <?}?>
		</table>
	</td><td id="oponent-details">
  <div class="user-menu">
    <? if(!isset($_SESSION['user']['id'])){?><button class="thoughtbot" onclick="$('#loading').show().find('img').hide();$('#fb-login,#tw-login').show();"><?=$lang_label['mpl_login']?></button>
    <? }else { ?><button class="thoughtbot right" onclick="showModalWindow('index.php?ajax=settings_window',598,519);"><?=$lang_label['mpl_settings']?></button><button class="thoughtbot left" onclick="window.location='functions/logout.php?logout'"><img src="<?=$_SESSION['user']['avatar']?>" width="48" height="48"><?=$lang_label['mpl_logout']?></button><button class="thoughtbot right" onclick="showModalWindow('index.php?ajax=chat_window',880,500);">Button 2</button><button class="thoughtbot right" onclick="showModalWindow('index.php?ajax=chat_window',880,500);"><?=$lang_label['mpl_chat']?></button><?}?>
  </div>
<?php
    for($i = 0; $i< (sizeof($opponents_data)-1)/5; $i++){
      $rank = (strpos($opponents_data[($i*5)],'-') === false)?array(0,$opponents_data[($i*5)]):explode('-',$opponents_data[($i*5)]);
      $oponent = getCharacterData($opponents_data[($i*5)+1]);
     $pers1 = new Personage($character_data);
     $pers2 = new Personage($oponent);
     $rez = SF_Calc::CalculateWin($pers1, $pers2);
      if($i == 0){ $current_oponent_lvl = $oponent[7]; $current_oponent_class = $oponent[29];}
   ?>
      <div class="data-container" id="oponent-<?=$rank[1]?>"<?=($i != 0)?' style="display:none;"':''?>>
          <div class="data-header">
            <img src="img/<?=strtolower(getClassName($oponent[29]))?>.png" style="position:absolute;top:13px;right:22px;padding:0;" />
            <div>
            <input type="text" name="character" value="<?=$opponents_data[($i*5)+1]?>" onKeyup="$(this).val('<?=$opponents_data[($i*5)+1]?>')">
            </div>
          </div>
          <div class="data-div">
          <div class="atr_class" val="<?=$oponent[29]?>"><?=getClassName($oponent[29])?></div>
          <div><?=$lang_label['ust_level']?>: <a title="<?=$oponent[8].'/'.$oponent[9]?>"><?=$oponent[7]?></a></div>
          <div><?=$lang_label['ust_strength']?>: <a<?=(($oponent[35]=='0')?'>':' title="+'.$oponent[35].'">').($oponent[35]+$oponent[30])?></a></div>
          <div><?=$lang_label['ust_dexterity']?>: <a<?=(($oponent[36]=='0')?'>':' title="+'.$oponent[36].'">').($oponent[36]+$oponent[31])?></a></div>
          <div><?=$lang_label['ust_intelligence']?>: <a<?=(($oponent[37]=='0')?'>':' title="+'.$oponent[37].'">').($oponent[37]+$oponent[32])?></a></div>
          <div><?=$lang_label['ust_constitution']?>: <a<?=(($oponent[38]=='0')?'>':' title="+'.$oponent[38].'">').($oponent[38]+$oponent[33])?></a></div>
          <div><?=$lang_label['ust_luck']?>: <a<?=(($oponent[39]=='0')?'>':' title="+'.$oponent[39].'">').($oponent[39]+$oponent[34])?></a></div>
          <div><?=$lang_label['ust_damage']?>: <?=round($oponent[146]*(1+getMainStat($oponent)/10)).'-'.round($oponent[147]*(1+getMainStat($oponent)/10)).'(<a>'.getDPS($oponent)?></a>)</div>
          <div><?=$lang_label['ust_hitpoints']?>: <a><?=getHP($oponent)?></a></div>
          <div><?=$lang_label['ust_critical']?>: <?=getCrit($oponent)?> (<b><a><?=getCrit($oponent,$character_data[7])?></a></b>)</div>
          <div><?=$lang_label['ust_res']?>: <a><?=getRes($oponent, $character_data[29])?></a></div>
          <div><?=$lang_label['ust_armor']?>: <a><?=getArmor($oponent)?></a><br><?=(($_script_debug == 1)?'<hr>'.calculateResultsFormula($character_data, $oponent):'')?></div>
          </div>
          <?=(($_script_debug == 1)?'<pre style="overflow:auto;height:200px;">'.implode("\n",$oponent).'</pre>':'')?>
          <script>
            $('<img src="img/<?=strtolower(getClassName($oponent[29]))?>.png" />').prependTo('#row-<?=$rank[1]?> td:eq(1)');
            coff = <?=$rez; //calculateResults($character_data, $oponent);//$rez;?>;
            $('#row-<?=$rank[1]?>').addClass('red-coff');
            if(coff > 50){$('#row-<?=$rank[1]?>').removeClass('red-coff').addClass('yellow-coff');}
            if(coff > 75){$('#row-<?=$rank[1]?>').removeClass('yellow-coff').addClass('green-coff');}
            if(coff > cur_coff) {$('.bold-coff').removeClass('bold-coff');$('#row-<?=$rank[1]?>').addClass('bold-coff');cur_coff = coff;}
            coff = (coff).toFixed(3);
            if(coff>0){coff= '+'+coff;}
            $('#row-<?=$rank[1]?> td:last').html(coff);
          </script>
      </div>
    <?}?>
    </td></tr></table>
  <?}else{?>
    	  </table>
      </td>
    </tr>
  </table>
 <?}?>
<script type="text/javascript">
<? if(isset($_SESSION['character'])){ ?>
  $("#table-ranks").tablesorter(); 
  <? if(isset($_SESSION['user']['id'])){ ?>
  $('#table-ranks th').eq(<?=$_SESSION['user']['settings']['sort_by']?>-1).click();
  <? }else{ ?>
  $('#table-ranks th').eq(0).click();
  <? } ?>
  $('#loading').hide();
  function calculateCrit(lvl){
    return ((<?=($character_data[39]+$character_data[34])?>*5)/(lvl*2)).toFixed(2);
  }
  
  function calculateRes(attr_class){
      if(attr_class == 1){ return '<?=getRes($character_data, 1)?>';}
      if(attr_class == 2){ return '<?=getRes($character_data, 2)?>';}
      if(attr_class == 3){ return '<?=getRes($character_data, 3)?>';}
  }
  
  $('#table-ranks tbody tr').click(function(){
    $('#oponent-details .data-container').hide();
    $('#oponent-'+$(this).attr('id').replace('row-','')).show();
    $('.current').removeClass('current');
    $(this).addClass('current');
    $('#my-crit').html(calculateCrit($('#oponent-'+$(this).attr('id').replace('row-','')+' a:first').html()));
    $('#my-res').html(calculateRes($('#oponent-'+$(this).attr('id').replace('row-','')+' .atr_class').attr('val')));
  });
  $('#my-crit').html(calculateCrit(<?=$current_oponent_lvl?>));
  $('#my-res').html('<?=getRes($character_data, $current_oponent_class)?>');
  $('#oponent-details .data-container .data-div div').mouseenter(function(){
    var index = $("#oponent-details .data-container:visible .data-div div").addClass('opacity').index(this);
    character_div = $('#character-details .data-container:visible .data-div > div').addClass('opacity').eq(index);
    svalue2 = character_div.addClass('act').removeClass('opacity').find('a').html();
    svalue = parseFloat($(this).find('a').html());
    svalue2 = parseFloat(svalue2);
    if( svalue === undefined){
      classAdd= '';
    }else{
      classAdd = ' yellow';
      character_div.addClass('yellow');
      if(svalue>svalue2){classAdd= ' green';character_div.removeClass('yellow').addClass('red');}
      if(svalue<svalue2){classAdd= ' red';character_div.removeClass('yellow').addClass('green');}
    }
    $(this).removeClass('opacity').addClass('act'+classAdd);
  });

  $('#character-details .data-container .data-div div').mouseenter(function(){
    var index = $("#character-details .data-container:visible .data-div div").addClass('opacity').index(this);
    character_div = $('#oponent-details .data-container:visible .data-div > div').addClass('opacity').eq(index);
    svalue2 = character_div.addClass('act').removeClass('opacity').find('a').html();
    svalue = parseFloat($(this).find('a').html());
    svalue2 = parseFloat(svalue2);
    if( svalue === undefined){
      classAdd= '';
    }else{
      classAdd = ' yellow';
      character_div.addClass('yellow');
      if(svalue>svalue2){classAdd= ' green';character_div.removeClass('yellow').addClass('red');}
      if(svalue<svalue2){classAdd= ' red';character_div.removeClass('yellow').addClass('green');}
    }
    $(this).removeClass('opacity').addClass('act'+classAdd);
  });
  
  $('.data-container .data-div div').mouseleave(function(){
    $(".data-div > div").removeClass('act opacity red yellow green');
  });
  $(window).scroll(function(){
      if($(window).scrollTop() > 30){
        $('#table-ranks thead tr').css({'position':'fixed','border':'1px solid #FFFFFF','margin-left':'-1px','width':'498px','border-bottom':'none'});
      }else{
        $('#table-ranks thead tr').css({'position':'static', 'border':'','width':'500px'});
      }
      if($(window).scrollTop() > 10){
        $('div.user-menu').css({'top':'4px','position':'fixed'});
      }else{
        $('div.user-menu').css({'top':'14px','position':'absolute'});
      }
  });
  $('body>img.filter-criteria').hide();
<?}else{?>
  $('form').prependTo('body');
  $('input[name="character"]').focus();
  $('body>img.filter-criteria').click(function(){
    if(!$(this).hasClass('act')){
        $('body>img.filter-criteria.act').removeClass('act');
        $(this).addClass('act');
        if($(this).hasClass('right')){
          $('input[name^="filter_criteria"]').val('group');
          $('input[name="character"]').css('text-align','right').focus();
        }else{
          $('input[name^="filter_criteria"]').val('user');
          $('input[name="character"]').css('text-align','left').focus();
        }
    }
  }).css('cursor','pointer');
<? } ?>
</script>
  <div id="modal-window-container"></div>
</body>
</html>
